package controller;


import dao.NoticeDao;
import entity.Notice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import service.NoticeService;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/Notice")
@Scope("prototype")
public class NoticeController {

    @Autowired
    private NoticeDao noticeDao;
    @Autowired
    public NoticeService noticeService;

    @RequestMapping("/query")
    @ResponseBody
    public Map<String,Object> query(Notice notice,@RequestParam(value = "pageNumber",defaultValue = "1",required = false) int pageNumber, @RequestParam(value = "pageSize",defaultValue = "5",required = false) int pageSize){
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("total",noticeDao.getCount(notice));
        map.put("rows",noticeService.query(notice.getNotTitle(),notice.getStartTime(),notice.getEndTime(),pageSize,pageNumber));
        return map;
    }

    @RequestMapping("/getNoticeById")
    @ResponseBody
    public Notice getNoticeById(int notid){
        return noticeDao.getNoticeById(notid);
    }


    @RequestMapping("/del")
    @ResponseBody
    public boolean del(int notId){
        return noticeDao.del(notId);
    }

    @RequestMapping("/update")
    @ResponseBody
    public boolean update(Notice notice){
        return noticeDao.update(notice);
    }

    @RequestMapping("/add")
    @ResponseBody
    public boolean add(Notice notice){
        return noticeDao.add(notice);
    }



}
